#include "QDialogTimer.h"

QDialogTimer::QDialogTimer(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
	diyUi();

	QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(slotUpdateTime()));
}

QDialogTimer::~QDialogTimer()
{
}

void QDialogTimer::setTimerValue(int value)
{
	ui.label_time->setText(QString("%1").arg(value));
}

void QDialogTimer::enableTimer(bool enable)
{
	if (enable)
	{
		m_timer.start(1000);
	}
	else
	{
		m_timer.stop();
	}
}

void QDialogTimer::slotUpdateTime()
{
	if (ui.label_time->text().toInt() - 1 >= 0)
	{
		ui.label_time->setText(QString("%1").arg(ui.label_time->text().toInt() - 1));
	}
	else
	{
		m_timer.stop();
		close();
	}
}

void QDialogTimer::diyUi()
{
	setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint));
	setStyleSheet("QDialog{background-color:rgb(255,255,255);border:none;color:white;}");
	ui.widget_bg->setStyleSheet("QWidget#widget_bg{background-image: url(Resources/Picture/timer.png);background-repeat:no-repeat;border:none;color:white;}");
}